"""
@author: 江同学呀
@file: object_field.py
@date: 2024/7/26 11:13
@desc:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/object.html

    A JSON object.
    一个 JSON 对象。
"""
from abc import ABC
from typing import Type, Union, Dict

from espc.common.field_common import Dynamic
from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField
from espc.orm.model.mapping.field.field_attribute import DynamicAttribute, EnabledAttribute, PropertiesAttribute
from espc.orm.model.properties import Properties
from espc.utils.build_add_attr import build_add_attr


class ObjectField(_BaseField, DynamicAttribute, EnabledAttribute, PropertiesAttribute, ABC):
    """
    对象 字段
    """
    _field_type: str = "object"

    def __init__(
            self, field_name: str = None, value: Dict = None, default: Dict = None, doc_values: bool = None,
            store: bool = None, dynamic: Union[str, bool, Dynamic] = None, enabled: bool = None,
            properties: Union[Properties, Dict] = None
    ):
        super().__init__(
            field_name=field_name, value=value, default=default, doc_values=doc_values, store=store, dynamic=dynamic,
            enabled=enabled, properties=properties
        )
        return

    def __get__(self, instance: _Base, owner: Type["ObjectField"]) -> Union["ObjectField", Dict]:
        return super(ObjectField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: Dict):
        super(ObjectField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> Dict:
        return self._value

    @value.setter
    def value(self, value: Dict):
        self._value: Dict = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {}
        return mapping




































